package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.ReportDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {

    @Autowired
    private ReportDao reportDao;

    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        //今天的日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //本周周一的日期
        String monday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday(new Date()));
        //本月一号的日期
        String first = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());


        //新增会员数
        Integer todayNewMember = reportDao.queryTodayNewMember(today);
        //总会员数
        Integer totalMember = reportDao.queryTotalMember();
        //本周新增会员数
        Integer thisWeekNewMember = reportDao.queryThisWeekNewMember(monday);
        //本月新增会员数
        Integer thisMonthNewMember = reportDao.queryThisWeekNewMember(first);//这里调上一个方法就行,只是名字有点别扭
        //今日预约数
        Integer todayOrderNumber = reportDao.queryTodayOrderNumber(today);
        //今日到诊数
        Integer todayVisitsNumber = reportDao.queryTodayVisitsNumber(today);
        //本周预约数
        Integer thisWeekOrderNumber = reportDao.queryThisWeekOrderNumber(monday);
        //本周到诊数
        Integer thisWeekVisitsNumber = reportDao.queryThisWeekVisitsNumber(monday);
        //本月预约数
        Integer thisMonthOrderNumber = reportDao.queryThisMonthOrderNumber(first);
        //本月到诊数
        Integer thisMonthVisitsNumber = reportDao.queryThisMonthVisitsNumber(first);

        //热门套餐
        List<Map<String, Object>> hotSetmeal = reportDao.findHotSetmeal();

        Map<String, Object> result = new HashMap<>();
        result.put("reportDate", today);
        result.put("todayNewMember", todayNewMember);
        result.put("totalMember", totalMember);
        result.put("thisWeekNewMember", thisWeekNewMember);
        result.put("thisMonthNewMember", thisMonthNewMember);
        result.put("todayOrderNumber", todayOrderNumber);
        result.put("todayVisitsNumber", todayVisitsNumber);
        result.put("thisWeekOrderNumber", thisWeekOrderNumber);
        result.put("thisWeekVisitsNumber", thisWeekVisitsNumber);
        result.put("thisMonthOrderNumber", thisMonthOrderNumber);
        result.put("thisMonthVisitsNumber", thisMonthVisitsNumber);
        result.put("hotSetmeal", hotSetmeal);

        return result;
    }
}
